package com.metacube.questionbank.service;

import org.springframework.beans.factory.annotation.Autowired;

import com.metacube.questionbank.dao.UserDAO;
import com.metacube.questionbank.dto.AnswerDTO;
import com.metacube.questionbank.dto.CommentDTO;
import com.metacube.questionbank.dto.QuestionDTO;
import com.metacube.questionbank.dto.UserDTO;

public class Validator {
	
	@Autowired
	UserDAO userDAO;
	
	public boolean checkUserData(UserDTO userDTO) {
		
		if(userDTO.getName().isEmpty() || userDTO.geteMail().isEmpty() || userDTO.getPassword().isEmpty()) {
			
			return false;
			
		} else {
			
			return true;
		}
	}

	public boolean checkUserLoginData(UserDTO userDTO) {
		
		return (userDTO.geteMail().isEmpty() || userDTO.getPassword().isEmpty());
		
	}
	
	
	
	public boolean checkChangePassword(String currentPassword, String password) {
		
		return (currentPassword.isEmpty() || password.isEmpty());
		
	}

	public boolean changePassword(String password, String currentPassword, int userId) {
		
		if(userDAO.changePassword(password, currentPassword, userId)==1) {
			
			return true;
		} else {
			
			return false;
		}
		
	}
	
	public boolean checkQuestion(QuestionDTO qDTO) {
		
		return (qDTO.getqTitle().isEmpty() || qDTO.getqTag().isEmpty());
		
	}

	public boolean checkAnswer(AnswerDTO aDTO) {
		
		return (aDTO.getaBody().isEmpty());
	}

	public boolean checkComment(CommentDTO commentDTO){
		return (commentDTO.getCommentBody().isEmpty());
	}
}
